﻿using System;
using System.Collections.Generic;
using WebComicPage.ComicWebServices;

namespace WebComicPage
{
    public partial class Search : System.Web.UI.Page
    {

        private readonly ComicWebServicesSoapClient _cwb = new ComicWebServicesSoapClient();
        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSearchByTitle_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;

            try
            {
                ComicBook book = _cwb.GetComicByTitle(txbSearchByTitle.Text);
                List<ComicBook> books = new List<ComicBook> {book};
                resultView.DataSource = books;
                resultView.DataBind();

            }
            catch (Exception)
            {
                lblError.Visible = true;
            }
        }

        protected void btnSearchByCategory_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;

            try
            {
                ComicBook[] books = _cwb.GetComicsByCategory(ddlSearchByCategory.SelectedValue);
                resultView.DataSource = books;
                resultView.DataBind();
            }
            catch (Exception)
            {
                lblError.Visible = true;
            }
        }

        protected void btnSearchByPublisher_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;
            try
            {
                ComicBook[] books = _cwb.GetComicsByPublisher(ddlSearchByPublisher.SelectedValue);
                resultView.DataSource = books;
                resultView.DataBind();
            }
            catch (Exception)
            {
                lblError.Visible = true;
            }
        }
    }
}